home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cc02.zip / CHGPASS.C < prev    next >
Text File  |  1985-08-28  |  5KB  |  116 lines

  1. /**
  2. * chgpass.c
  3. *
  4. * Allow the Password in the file PASSWRD.COM to be Changed
  5. * This program will first read in the ENTIRE PASSWRD.COM file
  6. * and extract the six (6) characters of the password.
  7. * The Password MUST be retyped exactly to be changed.
  8. * The PASSWRD.COM file is then written back out to the disk.
  9. *
  10. * I appologize for this not being a good example of 'C' coding
  11. * but, I wrote it without a manual handy and Strings and I still 
  12. * have a problem in 'C'.
  13. *
  14. * This program was written using Lattice 'C' Compiler ver 2.14
  15. *  
  16. *  Garth Kennedy    26 December 1984
  17. **/
  18. #include "_main.c"
  19.  
  20. main()
  21. {
  22.     static char pass[300];   /* data file for PASSWRD.COM */
  23.     static char *passf = "PASSWRD.COM"; /* file name */
  24.     char *p;                 /* pointer to first block of data */
  25.     FILE *fp;                /* file pointer */
  26.     int nact;                /* number of blocks read/written */
  27.     int n;                   /* number of blocks to be read/written */
  28.     int s;                   /* size of each block, in bytes */
  29.     char *mode = "rb+";        /* read/write a file -untranslated */
  30.     int ret;                  /* return code */
  31.     static char pw1[10],pw2[10];   /* temp holding for new passwords */
  32.     int i,j,k,l;
  33.     char c,d;
  34.      
  35.     s = 0xFE;                /* size of PASSWRD.COM */
  36.     n = 1;                   /* one block to be read */
  37.     p = &pass[0];            /* pointer to beginning of data file */
  38.     fp = fopen(passf,mode);    /* open the file */
  39.     nact = fread(p,s,n,fp);     /* read data block from disc */
  40.     ret = fclose(fp);       /* close the disc file */  
  41.  
  42.                     /* Print out CRT Header */
  43.     printf("  Change the Password Program                 26 Dec 1984\n\n");
  44.     printf("       This program is in the public domain the program may\n");
  45.     printf("       be copied and used without charge.\n");
  46.     printf("                Copyright KJ Consulting 1984\n\n");
  47.  
  48.     printf("\n       This program will allow the password to be changed");
  49.     printf("\n       in the password program PASSWRD.COM.\n");
  50.     printf("\n       You will be asked to 1.) Enter the current Password\n");
  51.     printf("                            2.) Enter the New Password\n");
  52.     printf("                            3.) Reenter the New Password\n");
  53.     printf("\n       At no time will any of the keystrokes appear on the CRT");
  54.     printf("\n       This was done to prevent problems with password 'stealing'");
  55.     printf("\n       At any point at which the Passwords dont match this program\n");
  56.     printf("       will terminate\n\n");
  57.  
  58.                     /* extract the Password characters from the .com file */
  59.     pw1[0] = pass[0xAC],pw1[1]= pass[0xB1],pw1[2] = pass[0xB6];
  60.     pw1[3] = pass[0xBB],pw1[4] = pass[0xC0],pw1[5] = pass[0xC5]; 
  61.  
  62.     i = 0,j = 0,l = 0;
  63.     printf("Please enter the current Password (6 characters) - ");
  64.     for (i = 0;i <= 5;i++)       /* manually enter to confirm */
  65.     {
  66.         c = getch();            /* check char by char */
  67.         printf(".");            /* j will be non-zero if wrong */
  68.         if (c != pw1[i])
  69.             j++;
  70.     }
  71.     printf("\n");
  72.     if (j != 0 )                /* didnt match */ 
  73.     {
  74.         printf("\n\n  !!! SORRY !!!  Wrong Password Entered \n\n");
  75.         exit(); 
  76.     }
  77.     while (l == 0)
  78.     {
  79.         printf("\nPlease Enter the New Password. Exactly Six (6) Characters - ");
  80.         for (i = 0;i <= 5;i++)
  81.         {
  82.             pw2[i] = getch();
  83.             printf(".");
  84.         }
  85.         printf("\n");
  86.         
  87.         j = 0;
  88.         printf("Please Reenter the New Password (6 characters) - ");
  89.         for (i = 0;i <= 5;i++)       /* manually enter to confirm */
  90.         {
  91.             c = getch();            /* check reentry character by char */
  92.             if (c != pw2[i])  j++;  /* j non-zero if no match */
  93.             printf(".");
  94.         }
  95.         printf("\n");
  96.         if (j == 0)
  97.             l = 999;            /* new password checks */
  98.     }                          /* end of if l == 0 */
  99.                        /* if j non-zero repeat the whole new password */
  100.                        /* loop - values will be reentered */
  101.     
  102.     printf("Saving the new Password\n\n");   /* passwords matched */
  103.     pass[0xAC] = pw2[0],pass[0xB1] = pw2[1],pass[0xB6] = pw2[2];
  104.     pass[0xBB] = pw2[3],pass[0xC0] = pw2[4],pass[0xC5] = pw2[5]; 
  105.  
  106.     s = 0xFE;                /* size of PASSWRD.COM */
  107.     n = 1;                   /* one block to be read */
  108.     p = &pass[0];            /* pointer to beginning of data file */
  109.     fp = fopen(passf,mode);    /* open the file */
  110.     nact = fwrite(p,s,n,fp);     /* read data block from disc */
  111.     ret = fclose(fp);       /* close the disc file */  
  112.  
  113.     exit();
  114. }
  115.  
  116.